webpage.js ➔ ... ➔ fs.writeFile   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
c 0
b 0
f 0
nc 2
dl 0
loc 7
rs 9.4285
nop 1
1
const fs = require('fs')  
2
const request = require('request')
3
4
function saveWebpage (url, filePath) {  
5
  return getWebpage(url, filePath)
0 ignored issues
show
Bug introduced by
The call to getWebpage seems to have too many arguments starting with filePath.
Loading history...
6
    .then(writeFile)
7
}
8
9
function getWebpage (url) {  
10
  return new Promise (function (resolve, reject) {
11
    request.get(url, function (err, response, body) {
12
      if (err) {
13
        return reject(err)
14
      }
15
16
      resolve(body)
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
17
    })
18
  })
19
}
20
21
function writeFile (fileContent) {  
22
  let filePath = 'page'
23
  return new Promise (function (resolve, reject) {
24
    fs.writeFile(filePath, fileContent, function (err) {
25
      if (err) {
26
        return reject(err)
27
      }
28
29
      resolve(filePath)
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
30
    })
31
  })
32
}
33
34
module.exports = {  
35
  saveWebpage
36
}